package com.scau402.system1.controller;

import com.scau402.common.core.domain.AjaxResult;
import com.scau402.common.core.page.TableDataInfo;
import com.scau402.system1.domain.dto.WmsCheckBoundOrderDTO;
import com.scau402.system1.domain.dto.WmsCheckOrderEditDTO;
import com.scau402.system1.domain.dto.WmsStopCheckDTO;
import com.scau402.system1.domain.po.WmsCheckBoundOrderPO;
import com.scau402.system1.domain.query.WmsCheckBoundOrderQuery;
import com.scau402.system1.service.IWmsCheckBoundOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

/**
 * 盘点模块控制器
 * @since 2024/1/27
 */

// TODO: 确认是权限字段否生效
// TODO: 根据DDD重构接口实现结构
@RestController
@RequestMapping("/system/checkOrder")
public class WmsCheckBoundOrderController {
    @Autowired
    private IWmsCheckBoundOrderService wmsCheckBoundOrderService;

    /**
     * 获取盘点单列表
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:query')")
    @PostMapping("/list")
    public TableDataInfo listCheckOrder(@RequestBody WmsCheckBoundOrderQuery query){
        return wmsCheckBoundOrderService.listCheckOrder(query);
    }

    /**
     * 创建盘点单
     * @param checkOrderDTO 创建盘点单必要信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:create')")
    @PostMapping("/create")
    public AjaxResult createCheckOrder(@RequestBody WmsCheckBoundOrderDTO checkOrderDTO){
        return wmsCheckBoundOrderService.createCheckOrder(checkOrderDTO);
    }

    /**
     * 确认盘点
     * @param barcode 确认盘点的翡翠条码
     * @param num 确认数量
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:confirm')")
    @PostMapping("/confirm")
    public AjaxResult confirm(@RequestParam Long checkOrderId,@RequestParam String barcode,@RequestParam @Min(value = 1,message = "盘点数量至少为1") Long num){
        return wmsCheckBoundOrderService.confirm(checkOrderId,barcode,num);
    }

    /**
     * 停止盘点
     * @param checkOrderId 盘点单号
     * @return 结果
     */
    @Deprecated
    @PreAuthorize("@ss.hasPermi('system:checkBound:stop')")
//    @PostMapping("/stop")
    public AjaxResult stopCheckOrder(@RequestParam Long checkOrderId){
        return wmsCheckBoundOrderService.stopCheckOrder(checkOrderId);
    }

    /**
     * 结束盘点
     * @param dto dto
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:stop')")
    @PostMapping("/stop")
    public AjaxResult stopCheckOrder(@RequestBody WmsStopCheckDTO dto){
        return wmsCheckBoundOrderService.stopCheckOrder(dto.getCheckOrderId());
    }

    /**
     * 获取盘点单详情
     * @param checkOrderId 盘点单号
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:detail')")
    @GetMapping("/detail")
    public AjaxResult getOrderDetail(@RequestParam Long checkOrderId){
        return wmsCheckBoundOrderService.getOrderDetail(checkOrderId);
    }

    /**
     * 获取盘点单对应翡翠的盘点详情
     * @param checkOrderId 盘点单号
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:jade')")
    @GetMapping("/jade")
    public TableDataInfo getJadesDetail(@RequestParam Long checkOrderId){
        return wmsCheckBoundOrderService.getJadesDetail(checkOrderId);
    }

    /**
     * 修改备注
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:checkBound:editRemark')")
    @PutMapping ("/editRemark")
    public AjaxResult editRemark(@RequestBody WmsCheckOrderEditDTO wmsCheckOrderEditDTO){
        return wmsCheckBoundOrderService.editRemark(wmsCheckOrderEditDTO);
    }
}
